package com.mrjy.maintain.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mrjy.common.entity.NewsInfo;
import com.mrjy.common.entity.UserInfo;
import com.mrjy.common.util.GlobalConstant;
import com.mrjy.maintain.bo.INewsInfoBo;

@Controller
@RequestMapping("/maintain/newsInfo")
public class NewsInfoController{
	@Resource
	private INewsInfoBo newsInfoBo;
	

	/**
	 * 显示信息
	 * @return
	 */
	@RequestMapping("/newsInfoList")
	@ResponseBody
	public Object newsInfoList(NewsInfo NewsInfo,HttpSession session) {
		UserInfo userInfo = ((UserInfo) session.getAttribute(GlobalConstant.USER_INFO));
		return newsInfoBo.queryPageNewsInfo(NewsInfo,userInfo);
	}
	
	/**
	 * 显示新闻类型信息
	 * @return
	 */
	@RequestMapping("/newsTypeList")
	@ResponseBody
	public Object newsTypeList() {
		
		return newsInfoBo.queryNewsTypeList();
	}
	
	
	/**
	 * 添加
	 * @return
	 */
	@RequestMapping("/addNewsInfo")
	@ResponseBody
	public Object insert(NewsInfo NewsInfo,HttpSession session){
		UserInfo userInfo = ((UserInfo) session.getAttribute(GlobalConstant.USER_INFO));
		NewsInfo.setUserId(userInfo.getId());
		newsInfoBo.insert(NewsInfo);
		return "ok";
	}
	/**
	 * 根据ID查询
	 * @return
	 */
	@RequestMapping("/queryById")
	@ResponseBody
	public Object queryById(int id) {
		return newsInfoBo.queryById(id);
	}
	/**
	 * 修改
	 * @param userNews
	 * @return
	 */
	@RequestMapping("/updateById")
	@ResponseBody
	public Object updateById(NewsInfo newsInfo,HttpSession session) {
		UserInfo userInfo = ((UserInfo) session.getAttribute(GlobalConstant.USER_INFO));
		newsInfo.setUserId(userInfo.getId());
		newsInfoBo.updateById(newsInfo);
		return "ok";
	}
	
	/**
	 * 删除
	 * @param ids
	 * @return
	 */
	@RequestMapping("/deleteByIds")
	@ResponseBody
	public Object deleteByIds(int[] ids) {		
		return newsInfoBo.deleteByIds(ids);
	}
	/**
	 * 禁用、起用
	 * @param ids
	 * @return
	 */
	@RequestMapping("/updateDisableFlag")
	@ResponseBody
	public Object updateDisableFlag(NewsInfo newsInfo) {		
		return newsInfoBo.updateDisableFlag(newsInfo);
	}
}
